{extend name='table'}

{block name="content"}
<div class="layui-tab layui-tab-card" style="margin-top: 0;">
    <div class="layui-tab-content">
        {include file='warehouse/warehouse_abroad/index_search'}
        <table id="HouseTable" data-url="{:sysuri()}" data-target-search="form.form-search"></table>
    </div>
</div>
{/block}

{block name='script'}
<script>
    $(function () {
        // 初始化表格组件
        $('#HouseTable').layTable({
            even: true, height: 'full',
            // sort: {field: 'id', type: 'desc'},
            toolbar: '#toolbarDemo',
            where: {type: '{$type|default=""}'},
            cols: [[
                {checkbox: true, fixed: true},
                /** {if $super} **/
                {field: 'company_name', title: '{:lang("公司")}', minWidth: 130, align: 'center'},
                /** {/if} **/
                {field: 'warehouse_c_name', title: '{:lang("仓库中文名称")}', minWidth: 130, align: 'center'},
                {field: 'warehouse_e_name', title: '{:lang("仓库英文名称")}', minWidth: 130, align: 'center'},
                {field: 'code', title: '{:lang("仓库编码")}', minWidth: 130, align: 'center'},
                {field: 'country_c_name', title: '{:lang("国家")}', minWidth: 130, align: 'center'},
                {field: 'contacts', title: '{:lang("仓库联系人")}', minWidth: 130, align: 'center'},
                {field: 'volume', title: '{:lang("仓库体积")}', minWidth: 130, align: 'center'},
                {field: 'sort', title: '{:lang("排序")}', width: 80, align: 'center'},
                {field: 'create_at', title: '{:lang("添加时间")}', width: 160, align: 'center'},
                {field: 'status', title: '{:lang("状态")}', minWidth: 110, align: 'center', templet: '#StatusSwitchTpl'},
                {toolbar: '#toolbar', align: 'center', width: 120, title: '{:lang("操作")}', fixed: 'right'},
            ]]
        });

        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (obj) {
            var data = {id: obj.value, status: obj.elem.checked ? 1 : 2};
            $.form.load("{:url('state')}", data, 'post', function (ret) {
                if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                    $('#HouseTable').trigger('reload');
                }); else {
                    $('#HouseTable').trigger('reload')
                }
                return false;
            }, false);
        });


    });
</script>
<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="{:lang('启用')}|{:lang('禁用')}" lay-filter="StatusSwitch" {{-d.status==1?'checked':''}}>
    <!--{else}-->
    {{-d.status ? '<b class="color-green">{:lang("启用")}</b>' : '<b class="color-red">{:lang("禁用")}</b>'}}
    <!--{/if}-->
</script>

<script type="text/html" id="toolbarDemo">
    <!--{if auth("add")}-->
    <button  data-modal='{:url("add")}' data-title="{:lang('添加仓库')}"  class='layui-btn layui-btn-sm layui-btn-primary'>{:lang('添加仓库')}</button>
    <!--{/if}-->
<!--    {if auth("remove")}-->
    <a data-confirm="{:lang('确定要删除吗？')}" data-table-id="HouseTable" data-action="{:url('remove')}" data-rule="id#{id}" class='layui-btn layui-btn-sm layui-btn-danger'>{:lang('批量删除')}</a>
<!--    {/if}-->
</script>

<!-- 数据操作工具条模板 -->
<script type="text/html" id="toolbar">
    <!--{if auth('edit')}-->
    <a class="layui-btn layui-btn-xs"  data-offset = "525px,240px" data-event-dbclick data-title="{:lang('编辑数据')}" data-modal='{:url("edit")}?id={{d.id}}'>{:lang('编 辑')}</a>
    <!--{/if}-->

    <!--{if auth("remove")}-->
    <a class="layui-btn layui-btn-danger layui-btn-xs" data-confirm="{:lang('确定要删除数据吗?')}" data-action="{:url('remove')}" data-value="id#{{d.id}}">{:lang('删 除')}</a>
    <!--{/if}-->
</script>
{/block}